package com.movie.controller;

import com.movie.model.Screening;
import com.movie.service.ScreeningService;
import com.movie.util.ScreeningRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/screening")
public class ScreeningController {

    @Autowired
    private ScreeningService screeningService;

    @GetMapping("/movie/{movieId}")
    @ResponseBody
    public List<Screening> getMovieScreenings(@PathVariable Integer movieId) {
        return screeningService.getScreeningsByMovie(movieId);
    }

    // 管理员场次管理接口
    @PostMapping("/add")
    @ResponseBody
    public String addScreening(@RequestBody ScreeningRequest request) {
        return screeningService.addScreening(request);
    }

    @GetMapping("/list")
    @ResponseBody
    public List<Screening> getAllScreenings() {
        return screeningService.getAllScreenings();
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Screening getScreeningById(@PathVariable Integer id) {
        return screeningService.getScreeningById(id);
    }

    @PutMapping("/{id}")
    @ResponseBody
    public String updateScreening(@PathVariable Integer id, @RequestBody ScreeningRequest request) {
        return screeningService.updateScreening(id, request);
    }

    @DeleteMapping("/{id}")
    @ResponseBody
    public String deleteScreening(@PathVariable Integer id) {
        return screeningService.deleteScreening(id);
    }
}